//
//  GouDetailsViewController.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/3/3.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "GouDetailsViewController.h"
#import "DouDetailsCell.h"
#import "DouSecondCell.h"
#import "TodoHttpManager.h"
@interface GouDetailsViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSArray *_titlArr;
    NSArray *_titlArr1;
    NSMutableDictionary *_dataDic;
  
   
    NSString *str;
    NSString *str1;
    NSString *str2;
    NSString *str3;
    NSString *str4;
    NSString *str5;
    NSString *str6;
    NSString *str7;
    NSString *str8;
    NSString *str9;
    NSString *str10;
    NSString *str11;
    NSString *str12;
    NSString *str13;
    NSString *str14;
    NSString *str15;
    NSString *str16;
    NSString *str17;
    NSString *str18;
    NSString *str19;
    NSString *str20;
    NSString *str21;
    NSString *str22;
    NSString *str23;
    NSString *str24;
    NSString *strID;
    NSString *strNum;

    
    
}
@property(nonatomic,strong)UITableView *tabView;

@property (nonatomic,strong) NSMutableArray *daArr;
@property (nonatomic,strong) NSMutableArray *daArr1;

@end

@implementation GouDetailsViewController

-(void)viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDGMZhuQianYUeDatials:) name:TDGMZhuRengouDatils object:nil];
    [_manager userGMRenGouDatialsWithID:_idStr];
}
-(void)didTDGMZhuQianYUeDatials:(NSNotification *)notid
{
    
    if (notid.object != nil)
    {
        int status = [[notid.object objectForKey:@"status"] intValue];
        if (status == 1)
        {
            _dataDic = [notid.object objectForKey:@"data"];

            str = [_dataDic objectForKey:@"rengou_name"];
           
            strNum =  [_dataDic objectForKey:@"rengou_phone"];
            str1 = [_dataDic objectForKey:@"id_card"];
            str2 = [_dataDic objectForKey:@"id_card_dz"];
            str3 =  [_dataDic objectForKey:@"rengou_time"];
            str4 = [_dataDic objectForKey:@"fy_name"];
            str5 =  [_dataDic objectForKey:@"dingjin"];
            str6 = [_dataDic objectForKey:@"sale_area"];
            str7 =  [_dataDic objectForKey:@"sale_price"];
            str8 = [_dataDic objectForKey:@"sale_price_all"];
            str9 =  [_dataDic objectForKey:@"acyh"];
            str10 = [_dataDic objectForKey:@"xieyi_price_all"];
            str11 = [_dataDic objectForKey:@"xieyi_price"];
            str12 = [_dataDic objectForKey:@"tbyh"];
            str13 = [_dataDic objectForKey:@"hetong_price_all"];
            str14 =  [_dataDic objectForKey:@"hetong_price"];
            
            str15 = [_dataDic objectForKey:@"pay_way"];//付款方式
            str16 =  [_dataDic objectForKey:@"should_pay_money"];//应缴首付
            str17 = [_dataDic objectForKey:@"loan_money"];//贷款金额
            str18 =  [_dataDic objectForKey:@"loan_type"];//贷款类型
            str19 = [_dataDic objectForKey:@"true_pay_money"];//实缴首付
            str20 =  [_dataDic objectForKey:@"owe_money"];//总欠首付
            str21 = [_dataDic objectForKey:@"sf_status"];//首付状态
            str22 =  [_dataDic objectForKey:@"ptf_status"];//代收费用状态
            str23 = [_dataDic objectForKey:@"sign_status"];//签约状态
            
            str24 = [_dataDic objectForKey:@"adviser"];//置业顾问
            
            
            _daArr = [[NSMutableArray alloc] initWithObjects:str,strNum,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15,str16,str17,str18,str19,str20,str21,str22,str23, nil];

            _daArr1 = [[NSMutableArray alloc] initWithObjects:str,strNum,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15,str16,str17,str18,str19,str20,str21,str22,str23,str24, nil];
           // NSLog(@"111-----%lu",(unsigned long)_daArr.count);
            
            
            [_tabView reloadData];
        }
        else
        {
            [_manager MakeMyselfAlert:@"获取失败" andIsNeedTitle:NO andShowTime:2];
        }
    }

    
}
-(void)viewWillDisappear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDGMZhuRengouDatils object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //self.title = @"认购";
     self.title = @"房源管理";
    _manager = [TodoHttpManager sharedManager];
    _dataDic = [[NSMutableDictionary alloc] init];
   

   
    _titlArr = @[@"认购姓名 :",@"联系电话",@"身份证号:",@"身份证地址 :",@"认购时间 :",@"认购房源 :",@"缴纳定金 :",@"销售面积 :",@"销售表价 :",@"表价总价 :",@"案场优惠 :",@"协议总价 :",@"协议单价 :",@"特别优惠 :",@"合同总价 :",@"合同单价 :", @"付款方式 :",@"应缴首付 :",@"贷款金额 :",@"贷款类型 :",@"实缴首付 :",@"总欠首付 :",@"首付状态 :",@"代收费用状态 :",@"签约状态 :"];

    _titlArr1 = @[@"认购姓名 :",@"联系电话",@"身份证号:",@"身份证地址 :",@"认购时间 :",@"认购房源 :",@"缴纳定金 :",@"销售面积 :",@"销售表价 :",@"表价总价 :",@"案场优惠 :",@"协议总价 :",@"协议单价 :",@"特别优惠 :",@"合同总价 :",@"合同单价 :", @"付款方式 :",@"应缴首付 :",@"贷款金额 :",@"贷款类型 :",@"实缴首付 :",@"总欠首付 :",@"首付状态 :",@"代收费用状态 :",@"签约状态 :",@"置业顾问:"];
    
    _tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, B_WIDTH, B_HEIGHT) style:UITableViewStylePlain];
    _tabView.delegate = self;
    _tabView.dataSource = self;
    _tabView.rowHeight = 44;

    //self.tabView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tabView];
 
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 3) {
        NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
        NSString *str0 = @"";
        if ([IDA isEqualToString: @"1"])
        {
            str0 = (NSString *)_daArr[indexPath.row];
        }else {
            str0 = (NSString *)_daArr1[indexPath.row];
        }
        NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};  //指定字号
        CGRect rect = [str0 boundingRectWithSize:CGSizeMake(LL_ScreenWidth - 117 - 15, MAXFLOAT)/*计算宽度时要确定高度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                       NSStringDrawingUsesFontLeading attributes:dic context:nil];
        return rect.size.height+24>44?rect.size.height+24:44;
    }
    return 44;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
 
    NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
    if ([IDA isEqualToString: @"1"])
    {
            return _titlArr.count;
    }
    else
    {
        return _titlArr1.count;
    }
   
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *cellIndent = @"";
    if (indexPath.row == 1)
    {
        cellIndent = @"CellA";
        DouSecondCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (cell ==nil)
        {
            cell = [[DouSecondCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndent];
           
            strNum =  [_dataDic objectForKey:@"rengou_phone"];
            cell.secondLab.text = [NSString stringWithFormat:@"%@",strNum.length>0?strNum:@""];
            [cell setUpUIPbone:[_dataDic objectForKey:@"rengou_phone"]];

        }

        cell.firstLab.text= @"联系电话:";
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//取消点击
        return cell;

    }
    else
    {
        cellIndent = @"CellB";
        DouDetailsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (cell ==nil)
        {
            cell = [[DouDetailsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndent];
   
         
        }
        if ([cell isKindOfClass:[DouDetailsCell class]])
        {
            if (_daArr.count != 0)
            {

                NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
                if ([IDA isEqualToString: @"1"])
                {
                    NSString *str0 = (NSString *)_daArr[indexPath.row];
                    if (indexPath.row == 3) {
                        NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};  //指定字号
                        CGRect rect = [str0 boundingRectWithSize:CGSizeMake(LL_ScreenWidth - 117 - 15, MAXFLOAT)/*计算宽度时要确定高度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                                       NSStringDrawingUsesFontLeading attributes:dic context:nil];
                        cell.rightHeight = rect.size.height + 9*2;
                        cell.rightStr = [NSString stringWithFormat:@"%@",str0];
                    }else {
                        cell.secondLab.text = [NSString stringWithFormat:@"%@",str0];
                    }
                    
                   
                }
                else
                {
                    NSString *str0 = (NSString *)_daArr1[indexPath.row];
                    if (indexPath.row == 3) {
                        NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};  //指定字号
                        CGRect rect = [str0 boundingRectWithSize:CGSizeMake(LL_ScreenWidth - 117 - 15, MAXFLOAT)/*计算宽度时要确定高度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                                       NSStringDrawingUsesFontLeading attributes:dic context:nil];
                        cell.rightHeight = rect.size.height;
                        cell.rightStr = [NSString stringWithFormat:@"%@",str0];
                    }else {
                        cell.secondLab.text = [NSString stringWithFormat:@"%@",str0];
                    }
                    
                    
                }
//                NSString *str0 = (NSString *)_daArr[indexPath.row];
//                cell.secondLab.text = [NSString stringWithFormat:@"%@",str0];
//
               // NSLog(@"jiciya-----%@",_daArr);
           }

        }

        
        NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
        if ([IDA isEqualToString: @"1"])
        {
           cell.firstLab.text = _titlArr[indexPath.row];
        }
        else
        {
            cell.firstLab.text = _titlArr1[indexPath.row];
        }
       
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//取消点击
        return cell;
        
  }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
